﻿using Models;
using System;
using System.Windows.Forms;
using VirtualGameBLL;

namespace VirtualGame
{
    public partial class FormLogin : Form
    {
        public FormLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            string id = textBoxLogin1.Text;
            string password = textBoxLogin2.Text;
            if (id.Length > 0 && password.Length > 0)
                if (UserManager.Login(id, password))
                {
                    this.Hide();
                } else {
                    textBoxLogin1.Text += " -- 密码错误";
                }
        }

        private void btnSignUp_Click(object sender, EventArgs e)
        {
            string id = textBoxSignUp1.Text;
            string name = textBoxSignUp2.Text;
            string password = textBoxSignUp3.Text;
            if (id.Length > 0 && name.Length > 0 && password.Length > 0)
                if(UserManager.AddUser(new User(id, name, password))) {
                    textBoxSignUp1.Text = "注册成功，请登录";
                }  else  {
                    textBoxSignUp1.Text = "注册失败，该账号已存在";
                }
        }
             
        private void FormLogin_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
    }
}
